/**
 * Created by Ren on 2015/6/3.
 */
Array.prototype.remove = function(obj) {
    var index = this.indexOf(obj);
    if (index > -1) {
        this.splice(index, 1);
    }
}
Array.prototype.removeALL = function()
{
    for(var i = 0; i < this.length; i++)
    {
        this.splice(i, this.length);
    }
    return this;
}
function isCollided(obj1, obj2)
{
    if(obj1&&obj2)
    {
        var cen1 = obj1.getCenter();
        var cen2 = obj2.getCenter();

        if(Math.abs(cen1.x - cen2.x) <= (obj1.width + obj2.width)/2 &&
            Math.abs(cen1.y - cen2.y) <= (obj1.height + obj2.height)/2)
        {
            return true;
        }
    }
    return false;
}
function isBossCollided(obj1, obj2)
{
    if(obj1&&obj2)
    {
        var cen1 = obj1.getCenter();
        var cen2 = obj2.getCenter();

        if(Math.abs(cen1.x - cen2.x) <= (obj1.width + obj2.width)/2 &&
            Math.abs(cen1.y - cen2.y) <= (obj1.height + obj2.height)/2)
        {
            return true;
        }
    }
    return false;
}
function isEnemyCollided(obj1, obj2)
{
    if(obj1&&obj2)
    {
        var cen1 = obj1.getCenter();
        var cen2 = obj2.getCenter();

        if(Math.abs(cen1.x - cen2.x) <= (obj1.dx + obj2.dx)/2 &&
            Math.abs(cen1.y - cen2.y) <= (obj1.dy + obj2.dy)/2)
        {
            return true;
        }
    }
    return false;
}
function drawImage2(ctx, img, ix, iy, iw, ih, x, y, r, w, h) {
    ctx.translate(w/2 + x, h / 2 + y);
    ctx.rotate(r);
    ctx.translate(0 - w / 2, 0 - h / 2);
    ctx.drawImage(img, ix, iy, iw, ih, 0, 0, w, h);
    ctx.translate(w / 2, h / 2);
    ctx.rotate(-r);
    ctx.translate(0 - w/2 - x, 0 - h/2 - y);
};
function drawImage1(ctx, img, ix, iy, w, h) {
    drawImage2(ctx, img, 0, 0, w, h, ix, iy, 0, w, h);
};
function Point(x, y)
{
    this.x = x;
    this.y = y;
}
function getWeight(w, h)
{
    return 10 * (w*h)/(53*55);
}